<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
          <div class="icon" v-for="item in page" :key="item.id">
            <div class="icon-img">
              <img class="icon-img-cont" :src="item.imgUrl" alt="">
            </div>
            <p class="icon-p">{{item.desc}}</p>
          </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
  export default {
    name: "Icons",
    props: {
      iconlist: Array
    },
    data() {
      return {
        swiperOption: {
          autoplay: false
        }
      }
    },
    computed: {
      pages() {
        const pages = []
        this.iconlist.forEach((item, index) => {
          const page = Math.floor(index / 8)
          if (!pages[page]) {
            pages[page] = []
          }
          pages[page].push(item)
        })
        return pages
      }
    }
  }
</script>

<style scoped>
  .icons {
    height: 0;
    overflow: hidden;
    background-color: #ffffff;
    padding-bottom: 50%;
  }

  .icon {
    position: relative;
    overflow: hidden;
    float: left;
    width: 25%;
    height: 0;
    padding-bottom: 25%;
    /*background-color: red;*/

  }

  .icon-img {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 22px;
    /*background-color: yellow;*/
    box-sizing: border-box;
    padding: 5px;
  }

  .icon-img-cont {
    height: 100%;
    display: block;
    margin: 0 auto;
  }

  .icon-p {
    position: absolute;
    height: 22px;
    bottom: 3px;
    left: 0;
    right: 0;
    line-height: 20px;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
